package com.example.brisk.controller;

import com.example.brisk.entity.Book;
import com.example.brisk.rpc.BookRpcService;
import com.example.brisk.vo.R;
import com.example.brisk.vo.req.BookSaveReqVo;
import com.example.brisk.vo.req.BookUpadateReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 此接口用于调用BookController，测试远程调用(rpc)。
 * 分别通过rpc方式调用了BookController的5个接口。
 * 调用关系：web -> 此接口 -> BookController。
 */
@Api(value = "book(rpc)", tags = "book rpc api")
@RestController
@RequestMapping("/rpc/book")
public class BookRpcController {

    @Autowired
    private BookRpcService bookRpcService;

    @ApiOperation(value = "获取详情", notes = "传入id")
    @GetMapping("/{id}")
    public R<Book> getBook(@PathVariable Integer id){
        return bookRpcService.getBookById(id);
    }

    @ApiOperation(value = "创建book", notes = "传入book")
    @PostMapping("")
    public R saveBook(@RequestBody BookSaveReqVo vo){
        return bookRpcService.saveBook(vo);
    }

    @ApiOperation(value = "编辑book", notes = "传入book")
    @PutMapping("")
    public R updateBook(@RequestBody BookUpadateReqVo vo){
        return bookRpcService.updateBook(vo);
    }
    @ApiOperation(value = "删除book", notes = "传入id")
    @DeleteMapping("/{id}")
    public R removeBook(@PathVariable Integer id){
        return bookRpcService.removeBook(id);
    }

    @ApiOperation(value = "获取book列表", notes = "")
    @GetMapping("/list")
    public R<List<Book>> getBookList(){
        return bookRpcService.getBookList();
    }
}
